package com.ruoyi.common.enums.wecom;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomChatGroupMemJoinSceneEnum {

    /**
     * 入群场景枚举
     */
    INVITE(0, "由成员邀请入群"),
    QR_CODE(3, "通过扫描群二维码入群");

    private final Integer code;
    private final String desc;

    private static final Map<Integer, WecomChatGroupMemJoinSceneEnum> ENUM_MAP;

    static {
        WecomChatGroupMemJoinSceneEnum[] values = values();
        Map<Integer, WecomChatGroupMemJoinSceneEnum> enToCn = new HashMap<>(values.length);
        for (WecomChatGroupMemJoinSceneEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomChatGroupMemJoinSceneEnum getEnumByType(Integer type) {
        WecomChatGroupMemJoinSceneEnum wecomChatGroupMemJoinSceneEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomChatGroupMemJoinSceneEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomChatGroupMemJoinSceneEnum;
    }


}
